<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/public/js/contract/lovcy.js"></script>
<script type="text/javascript" src="/public/js/contract/lovMateriel.js"></script>
<script type="text/javascript" src="/public/js/contract/lovcyPayment.js"></script>
<script type="text/javascript" src="/public/js/contract/lovcyEmployee.js"></script>
<meta charset="UTF-8">
<title>合同新增</title>
</head>
<body>
	<div class="tab">
		<ul class="tabtit" id="projecthome">
			<li class="current">返回列表</li>
		</ul>
	</div>
	<div class="ittab">
				<div class="usein">
					<form id="addDataFormHeader" name="addDataFormHeader">
					<input type="hidden" id="deleteIds" name="deleteIds" />
						<h2 class="mt10">合同头信息<b></b></h2>
							<table class="table4"  width="100%" border="1" cellspacing="0" cellpadding="0" >
						<tr>
							<td><span class="red">*</span>合同编号:</td>
							<td >
								<input id="contractNum" name="contractNum"  type="text" class="input_text w200"/>
							</td>
							<td><span class="red">*</span>签订日期:</td>
							<td >
								<input class="easyui-datebox" style="width: 200px; height: 22px;" name="signingDate" editable="false" id="signingDate"  type="text"  />
							</td>
							<td  >施工日期:</td>
							<td>
								<input class="easyui-datebox" style="width: 200px; height: 22px;" name="implementDate" editable="false" id="implementDate"  type="text"  />
							</td>
						</tr>
						<tr>
							<td><span class="red">*</span>客户名称:</td>
							<td >
								<input class="input_text w200" style="width: 200px; height: 22px;" name="customerId"   id="customerId"  type="hidden"  />
								<input class="input_text w200" style="width: 200px; height: 22px;" name="customerName"  onclick="queryCustomer()"  id="customerName"  type="text"  />
								<!-- <input class="input_text w200" style="width: 200px; height: 22px;" name="customerName"  id="customerName"  type="text"  /> -->
							</td>
							<td>完工日期:</td>
							<td >
								<input class="easyui-datebox" style="width: 200px; height: 22px;" name="paramValue" editable="false" id="paramValue"  type="text"  />
							</td>
							<td >总金额:</td>
							<td >
								<input type="text"   id="TOTAL_AMOUNT"  disabled="true" name="TOTAL_AMOUNT" class="input_text w200" />
							</td>
						</tr>
						<tr>
							<td ><span class="red">*</span>付款条款:</td>
							<td >
								<input type="text"   id="paymentTermId" onclick="payment()" name="paymentTermId" class="input_text w200" />
							</td>
							<td ><span class="red">*</span>状态:</td>
							<td >
								<select id="status" class="easyui-combobox w200" name="status">
									<option value="签订">签订</option>
									<option value="完成">完成</option>
								</select>
								<!-- <input type="text"   id="status"   name="status" class="input_text w200" /> -->
							</td>
							<td >销售员名称:</td>
							<td >
								<input class="input_text w200" style="width: 200px; height: 22px;" name="salesmanId"   id="salesmanId"  type="hidden"  />
								<input class="input_text w200" style="width: 200px; height: 22px;" name="salesmanName"    id="salesmanName"  type="text"  />
							</td>
						</tr>
						<tr>
							<td >合同附件:</td>
							<td >
								<input type="text"   id="contractAttachmentId"  disabled="true" name="contractAttachmentId" class="input_text w200" />
							</td>
							<td >备注:</td>
							<td colspan="3">
								<input type="text"   id="remark"  name="remark" class="input_text w200" />
							</td>
						</tr>
					</table>
					</form>
				</div>
		</div>
		<br><br>
		
		
	 <div   style="overflow:scroll;display:block;">
			<h3>
				<span>合同行信息</span>
			</h3>
			<div align="right">
				<a href="javascript:void(0)"  onclick="addline()">新增行</a>
				<a href="javascript:void(0)"  onclick="deleteLine()">删除行</a>
			</div>
				<table id="fixedThead" style="width: 1185px" cellpadding="1" border="1" cellspacing="1">
					<tr>
		               		<td id="checkAllTd" style="width: 50px;" class="bgColor_eee">全选<input id="selectAll" name="checkAll" type="checkbox"></td>
							<td style="width: 35px;" class="bgColor_eee">NO.</td>
							<td style="width: 80px;" class="bgColor_eee">合同行号</td>
							<td style="width: 80px;" class="bgColor_eee">物料编码</td>
							<td style="width: 80px;" class="bgColor_eee">物料名称</td>
							<td style="width: 80px;" class="bgColor_eee">版本编号</td>
							<td style="width: 80px;" class="bgColor_eee">版本名称</td>
							<td style="width: 80px;" class="bgColor_eee">版本型号</td>
							<td style="width: 80px;" class="bgColor_eee">数量</td>
							<td style="width: 105px;" class="bgColor_eee">销售单价</td>
							<td style="width: 150px;" class="bgColor_eee">施工费</td>
							<!-- <td style="width: 150px;" class="bgColor_eee">施工费2</td> -->
							<td style="width: 107px;" class="bgColor_eee">配件费</td>
							<td style="width: 105px;" class="bgColor_eee">金额</td>
						<!--  	<td style="width: 95px;" class="bgColor_eee" style="display:none">税率</td>
							<td style="width: 105px;" class="bgColor_eee" style="display:none">税额</td>
							<td style="width: 105px;" class="bgColor_eee" style="display:none">含税金额</td>	  -->
							<td style="width: 155px;" class="bgColor_eee">备注</td>
					 </tr>
				</table>
				<!-- <div id="lineTrs" >
					<table id="save_lines" style="width: 1185px" cellpadding="1"  border="1" cellspacing="1">
				     <tr></tr>
			         </table>
				</div> -->
	</div>
	
		<div class="usein" align="center">
			<a href="javascript:;" class="add btn btn-primary ml10 funcbtn add_user">保存</a>
			<a href="javascript:;" class="empty btn btn-danger ml10 funcbtn select_user"> 取消</a>
		</div>
		
<!-- 弹出窗口 -->
<div id="user_dialogbox" class="pop">
	<div class="usein">
		<h2 class="mt10">基本信息<b></b></h2>
		<table class="table4" width="100%" border="0" cellspacing="0" cellpadding="0" >
			<tr>
				<td>客户名称</td>
				<td class="tl">
					<input id="customerName" type="text" class="input_text w200"/>
				</td>
				<td>联系方式</td>
				<td class="tl">
					<input id="customerPhone" type="text" class="input_text w200"/>
				</td>
				<td class="tl">
					<a href="javascript:;" class="check btn btn-info ml10 funcbtn select_user">查询</a>
				</td>
			</tr>
		</table>
	</div>
	<div >
	<table class="easyui-datagrid" id="customerGrid"></table>
	</div>
</div>

<div id="wuliao_dialogbox" class="pop">
	<div class="usein">
		<h2 class="mt10">基本信息<b></b></h2>
		<table class="table4" width="100%" border="0" cellspacing="0" cellpadding="0" >
			<tr>
				<td>物料名称</td>
				<td class="tl">
					<input id="materielName" type="text" class="input_text w200"/>
				</td>
				<!-- <td>物料类别</td>
				<td class="tl">
					<input id="materielTypeName" type="text" class="input_text w200"/>
				</td> -->
				<td class="tl">
					<a href="javascript:;" class="check btn btn-info ml10 funcbtn select_user">查询</a>
				</td>
			</tr>
		</table>
	</div>
	<div >
	<table class="easyui-datagrid" id="wuliaoGrid"></table>
	</div>
</div>

<!-- 弹出窗口 -->
<div id="buyer_dialogbox" class="pop">
	<div class="usein">
		<h2 class="mt10">基本信息<b></b></h2>
		<table class="table4" width="100%" border="0" cellspacing="0" cellpadding="0" >
			<tr>
				<td>姓名</td>
				<td class="tl">
					<input id="employeeNameQuery" type="text" class="input_text w200"/>
				</td>
				<td class="tl">
					<a href="javascript:;" class="buyerQuery btn btn-info ml10 funcbtn select_user" id='buyerQuery'>查询</a>
				</td>
			</tr>
		</table>
	</div>
	<div >
	<table class="easyui-datagrid" id="buyerGrid"></table>
	</div>
</div>

<div id="fk_dialogbox" class="pop">
	<div class="usein">
		<h2 class="mt10">基本信息<b></b></h2>
		<table class="table4" width="100%" border="0" cellspacing="0" cellpadding="0" >
			<tr>
				<td>付款条款名称</td>
				<td class="tl">
					<input id="paymentTermName" type="text" class="input_text w200"/>
				</td>
				<td class="tl">
					<a href="javascript:;" class="check btn btn-info ml10 funcbtn select_user">查询</a>
				</td>
			</tr>
		</table>
	</div>
	<div >
	<table class="easyui-datagrid" id="fkGrid"></table>
	</div>
</div>
</body>
<script type="text/javascript" src="/public/js/sysparams/validate.js"></script>
<script type="text/javascript" src="/public/js/common.js"></script>
<script type="text/javascript" src="/public/bower_components/jquery/jquery.js"></script>
<script type="text/javascript" src="/public/bower_components/jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/public/bower_components/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/public/js/contract/addContract.js"></script>
<script type="text/javascript">
var su = 1;
function addline() {
	var tbl = document.getElementById("fixedThead");
	var rowSize = tbl.rows.length;
	var row = tbl.insertRow(rowSize);
	var cell0 = row.insertCell(0);
	var cell1 = row.insertCell(1);
	var cell2 = row.insertCell(2);
	var cell3 = row.insertCell(3);
	var cell4 = row.insertCell(4);
	var cell5 = row.insertCell(5);
	var cell6 = row.insertCell(6);
	var cell7 = row.insertCell(7);
	
	var cell8 = row.insertCell(8);
	var cell9 = row.insertCell(9);
	var cell10 = row.insertCell(10);
	var cell11 = row.insertCell(11);
	var cell12 = row.insertCell(12);
	var cell13 = row.insertCell(13);
	/* var cell9 = row.insertCell(9);
	var cell10 = row.insertCell(10);
	var cell11 = row.insertCell(11); 
	var cell12 = row.insertCell(12); */
	cell0.innerHTML = "<input   type='checkbox' name='checkLines' style='width:35px'  /> ";
	cell1.innerHTML = su;
	cell2.innerHTML = "<input   name='contractLineNum_"+su+"' id='contractLineNum_"+su+"' style='width:120px' />"//合同行号
	cell3.innerHTML = "<input   name='segment1_"+su+"' id='segment1_"+su+"' style='width:50px' readonly='true'/>"//物料编码
	cell4.innerHTML = "<input   name='finishedGoodsId_"+su+"' id='finishedGoodsId_"+su+"' style='width:120px'  type='hidden'/><input   name='finishedGoodsName_"+su+"' onclick='finishedGoods("+su+")' id='finishedGoodsName_"+su+"' style='width:120px' />"//成品id
	cell5.innerHTML = "<input   name='materielVersionNum_"+su+"' id='materielVersionNum_"+su+"' style='width:50px' readonly='true'/>"//版本编号
	cell6.innerHTML = "<input   name='materielVersionName_"+su+"' id='materielVersionName_"+su+"' style='width:50px' readonly='true'/>"//版本名称
	cell7.innerHTML = "<input   name='materielVersionModel_"+su+"' id='materielVersionModel_"+su+"' style='width:50px' readonly='true'/>"//版本型号
	
	cell8.innerHTML = "<input   name='quantity_"+su+"' id='quantity_"+su+"' style='width:50px' onblur='sum("+su+")'/>"//数量
	cell9.innerHTML = "<input   name='salesUnitPrice_"+su+"' id='salesUnitPrice_"+su+"'  style='width:100px' onblur='sum("+su+")'/>"//销售单价
	cell10.innerHTML = "<input   name='constructionCost1_"+su+"' id='constructionCost1_"+su+"' style='width:100px' onblur='sum("+su+")'/>"//施工费1
	/* cell6.innerHTML = " <input   name='constructionCost2_"+su+"'  id='constructionCost2_"+su+"' style='width:100px' /> "//施工费2 */
	cell11.innerHTML = "<input   name='constructionCost3_"+su+"' id='constructionCost3_"+su+"' style='width:100px' onblur='sum("+su+")'/>"//配件费
	cell12.innerHTML = "<input   name='totalAmount_"+su+"' id='totalAmount_"+su+"' style='width:100px' readonly='true'/>"//总金额
	/* cell9.innerHTML = "<select name='taxRate_"+su+"' id='taxRate_"+su+"' style='width:100px'><option value='请选择' >请选择</option><option value='0'>0%</option><option value='0.03'>3%</option><option value='0.06'>6%</option><option value='0.11'>11%</option><option value='0.13'>13%</option><option value='0.17'>17%</option></select>"//税率
	cell10.innerHTML = "<input   name='taxmoneyNumber_"+su+"' id='taxmoneyNumber_"+su+"'  style='width:100px' />"//税额
	cell11.innerHTML = "<input   name='intaxmoneyNumber_"+su+"' id='intaxmoneyNumber_"+su+"'  style='width:100px' />"//含税金额 */
	cell13.innerHTML = "<input   name='remark_"+su+"' id='remark_"+su+"'  style='width:100px' />"//备注
	var index = document.getElementById("fixedThead").getElementsByTagName('tr').length;
	su++;
}

function sum(su){
	
	
	var quantity="quantity_"+su;
	var salesUnitPrice="salesUnitPrice_"+su;
	var constructionCost1="constructionCost1_"+su;
	var constructionCost3="constructionCost3_"+su;
	
	/* var reg = /^[0-9]+[0-9]*$/;
	if(!reg.test($("#"+quantity+"").val()) && !reg.test($("#"+salesUnitPrice+"").val())&& !reg.test($("#"+constructionCost3+"").val())&& !reg.test($("#"+constructionCost1+"").val()) ){
		//$.messager.alert('提示',"输入不合法，请输入数字！",'info');
		alert("输入不合法，请输入数字！");
		return false;
	} */
	
	var totalAmount= $("#"+quantity+"").val() * $("#"+salesUnitPrice+"").val() ;
	if($("#"+constructionCost1+"").val()!=""){
		totalAmount=totalAmount+parseFloat($("#"+constructionCost1+"").val());
	}
	if($("#"+constructionCost3+"").val()!=""){
		totalAmount=totalAmount+parseFloat($("#"+constructionCost3+"").val());
	}
	$("#totalAmount_"+su).val(totalAmount);
	
	calcSum();
}

function calcSum() {
	var valueTable = document.getElementById("fixedThead");
	var table_tr = valueTable.getElementsByTagName('tr');
	// lookupCodeArr = [];
	var sumAmount = 0.00;
	for (var i = 1; i < table_tr.length; i++) {
		var inputParam = table_tr[i].getElementsByTagName('input');
		// 行的金额
		sumAmount = Number(sumAmount) + Number(inputParam[12].value);
	}
	$("#TOTAL_AMOUNT").val(sumAmount);
}


function deleteLine() {
	var deleteIds = "";
	var ckbs = $("input[name='checkLines']:checked");
	if (ckbs.size() == 0) {
		$.messager.alert('删除指定行', '要删除指定行，需选中要删除的行！', 'info');
		return;
	} else {
		ckbs.each(function() {
			if ($(this).val() != "") {
				deleteIds = deleteIds + $(this).val() + ",";
			}
			$(this).parent().parent().remove();
		});
		$("#deleteIds").val(deleteIds);
	}
}

</script>
</html>